package archi.filemanager;

import java.io.*; // Input/output depuis JDK 1.0
import java.nio.*; // Input/output depuis 1.4
import java.util.ArrayList;

import javax.tools.FileObject;

public class FileManager {
	
	protected String pathname;
	protected String filename;
	protected ArrayList<File> filesInMemory = new ArrayList<File>();

	public FileManager() {
		pathname = "c:\\"; 
	}
	
	FileManager(String path){
		
		pathname = path;
	}
	
	protected int loadFile(String path){
		
		File myfile = new File(path);
		this.filename = myfile.getName();
		this.filesInMemory.add(myfile);
		return 0;
	}
	
	protected int fileWrite(String filename) throws IOException{
		
			
		File myfile = filesInMemory.get(0);
		FileInputStream in = new FileInputStream(myfile);
		
		FileOutputStream out = new FileOutputStream(filename);
		
		byte[] buf = new byte[1024];
		int len;
		while((len = in.read(buf)) > 0){
			out.write(buf, 0, len);
		}
		
		

		
//		BufferedWriter fileBuffer = new BufferedWriter(out);
//		
//		File myfile = filesInMemory.get(0);
//		//File myfile = new File(this.pathname);
//		filesInMemory.remove(myfile);
//		
//		FileOutputStream out = new FileOutputStream(myfile);
//		
		return 0;
	}
	
	
}
